#include "StdAfx.h"
#include "move_handler.h"
namespace fly {

	namespace jld{

		namespace server {


			move_handler::move_handler()
				:handler()
			{
				target_ = T_SYN_TO;
			}

			bool move_handler::handle_recv(recv_buf& recv_buf, send_buf& send_buf, conn_info& conn_info)
			{
				if (MOVE != recv_buf.pid())
				{
					return handler::handle_recv(recv_buf, send_buf, conn_info);
				}
				LOG_INFO("Handle move");
				Move move;
				if (0 == recv_buf.buf().size())
				{
					move.set_category(CHARACTER);
					move.set_uid(conn_info.account());
					State* state = move.mutable_state();
					state->set_cur_time(timestamp->cur_mill_sec());
					Vector* cur_pos = state->mutable_cur_pos();
					cur_pos->set_x(20);
					cur_pos->set_y(20);
					Vector* pur_pos = state->mutable_pur_pos();
					pur_pos->set_x(20);
					pur_pos->set_y(20);
					return send_buf.serialize_to_send(MOVE, T_SYN_BOTH, move);
				}

				if(!recv_buf.parse_from_recv(move))
				{
					LOG_ERR("Parse move faild");
					return false;
				}
				move.set_uid(conn_info.account());
				return send_buf.serialize_to_send(MOVE, target_, move);
			}


		}
	}
}